<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        window.onload=function (){

            var btn = document.getElementById("btn1")
            btn.onclick = function () {
                alert("按钮单击了")
            }
        }
          
        
    </script>

</head>

<body >

    <button id="btn1">按钮</button>


</body>

</html>